<template>
	<view class="container">
		<view class="placeholder" v-if="placeholder" :style="{height: `${navi_Height}px`}"></view>
		<view
			id="main"
			class="main"
			:style="{
				background: navi_background,
				height: height ? `${height}rpx` : '',
				transform: slideFlag&&slideEnable?`translateY(${-getScrollDis}rpx)`:'translateY(0rpx)',
				transition: `all ${slide_rotation}s ease 0s`
			}"
		>
			<view class="head" :style="{height: `${pageInfo.headHeight}rpx`, background: head_background}">
				<view 
					class="titleBox"
					:style="{
						height:`${pageInfo.capsuleHieght}rpx`,
						marginTop: `${pageInfo.capsuleTop}rpx`,
						paddingLeft: `${titlePaddingLeft}rpx`,
						paddingRight: `${titlePaddingLeft}rpx`,
						transform: slideFlag&&slideEnable?`translateY(${-getScrollDisTitle}rpx)`:'translateY(0rpx)',
						transition: `all ${slide_rotation} ease 0s`
					}"
				>
					<slot name="title">
						<view class="leftIcon" @click="goback">
							<u-icon name="arrow-left" :color="color" size="20" v-if="isShowBackArrow"></u-icon>
						</view>
						<text class="headLine" :style="{color: color}">{{title}}</text>
					</slot>
				</view>
			</view>
			<view
				class="slide_content"
				:style="{width: slideFlag&&slideEnable?'560rpx':'100%'}"
				id="slide"
			>
				<slot name="slide"></slot>
			</view>
			<view class="head_stricky" id="stricky">
				<slot></slot>
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		name:"customHead",
		props: {
			title: {
				type: String,
				default: ''
			},
			titlePaddingLeft: {
				type: Number,
				default: 0
			},
			isShowBackArrow: {
				type: Boolean,
				default: false
			},
			navi_background: {
				type: String,
				default: ''
			},
			slideFlag: {
				type: Boolean,
				default: false
			},
			color: {
				type: String,
				default: "#000"
			},
			placeholder: {
				type: Boolean,
				default: false
			},
			height: {
				type: Number,
				default: 0
			},
			head_background: {
				type: String,
				default: ''
			},
			slide_rotation: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				slideEnable: false,
				pageInfo: {},
				navi_Height: 0
			};
		},
		computed: {
			getScrollDis () {
				return this.pageInfo.capsuleHieght + app.globalData.headPaddingBottom;
			},
			getScrollDisTitle () {
				return this.pageInfo.capsuleBottom;
			}
		},
		methods: {
			getContentSize () {
				let slideInfo = uni.createSelectorQuery().in(this);
				slideInfo.select("#slide").boundingClientRect((slideRes)=>{
					if (slideRes.height) {
						this.slideEnable = true;
					}
				}).exec()
				let mainInfo = uni.createSelectorQuery().in(this);
				mainInfo.select("#main").boundingClientRect((mainRes)=>{
					this.navi_Height = mainRes.height;
					this.$bus.$emit('setNaviHeight', mainRes.height);
				}).exec()
			},
			goback () {
				uni.navigateBack()
			},
		},
		mounted () {
			this.pageInfo = app.globalData;
			
			if (!this.height) {
				this.$nextTick(() => {
					setTimeout(() => {
						this.getContentSize();
					}, 50)
				})
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container{
		width: 100%;
		
		.placeholder{
			width: 100%;
		}
		
		.main{
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 9999;
			// transition: all 0.3s ease 0s;
				
			.head{
				width: 100%;
				display: flex;
				flex-direction: column;
				box-sizing: border-box;
				position: relative;
				
				.titleBox{
					width: 100%;
					display: flex;
					justify-content: flex-start;
					align-items: center;
					font-size: 36rpx;
					box-sizing: border-box;
					position: relative;
					// transition: all 0.3s ease 0s;
					
					.leftIcon{
						width: 80rpx;
						height: 100%;
						display: flex;
						align-items: center;
					}
					.title{
						width: 100%;
						height: 100%;
						box-sizing: border-box;
						display: flex;
						align-items: center;
					}
					
					.headLine{
						padding: 0 10rpx;
						position: absolute;
						left: 50%;
						transform: translateX(-50%);
					}
				}
			}
			.slide_content{
				width: 100%;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 36rpx;
				box-sizing: border-box;
				transition: all 0.3s ease 0s;
			}
		}
	}
	
	
</style>